home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.lib;
-
- import sub_arctic.output.drawable;
- import sub_arctic.constraints.std_encoding_consts;
- import sub_arctic.constraints.std_constraint_impl;
- import sub_arctic.lib.manager;
- import sub_arctic.lib.sub_arctic_error;
- import java.awt.Rectangle;
- import java.awt.Point;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Color;
- import java.util.Vector;
-
- /**
- * An interface_pred predicate class that performs a semantic redraw action
- * for a semantic lens. In this case the object draws debugging information
- * about the constraint dependency graph of each object (along with a class
- * name tag and bounding box). This predicate expects a sem_draw_context
- * object as its parameters argument. This predicate is executed for its
- * side effect only and always returns false.
- *
- * @see sub_arctic.lib.base_interactor#traverse_and_collect
- * @author Scott Hudson
- */
- public class cgraph_sem_draw extends nametag_sem_draw
- implements interactor_pred, interactor_consts{
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Unique id for this drawing traversal */
- public static final int id = manager.unique_int();
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Full constructor.
- * @param Font fnt the font to draw tags in.
- * @param Color c the color to draw tags and borders in.
- */
- public cgraph_sem_draw(Font fnt, Color c)
- {
- /* establish color */
- set_tag_color(c);
-
- /* establish font and metrics object */
- set_font(fnt);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Constructor using default font and tag color. */
- public cgraph_sem_draw()
- {
- /* use already initialized font to also set up metrics object */
- set_font(_font);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Perform the predicate test.
- *
- * @param obj the interactor the predicate is drawing.
- * @param parameters a sem_draw_context object containing the a drawable
- * object and other bookkeeping needed for drawing.
- * @return false in all cases.
- */
- public boolean test(interactor obj, Object parameters)
- {
- sem_draw_context context;
- String tag;
- Rectangle bound;
- int sz_w, sz_h, last_dot;
- int wv, hv;
-
- /* type check the parameters */
- if (!(parameters instanceof sem_draw_context))
- throw new sub_arctic_error("Non-sem_draw_context object passed as parameter");
-
- /* don't draw semantic lens or semantic lens parent objects */
- if (obj instanceof semantic_lens || obj instanceof semantic_lens_parent)
- return false;
-
- /* let superclass draw tag and bounding box */
- super.test(obj, parameters);
-
- /* extract drawing context */
- context = (sem_draw_context)parameters;
-
- /* extract object size then draw dependency edges for each constraint */
- wv = obj.w();
- hv = obj.h();
-
- /* draw x constraint edges */
- draw_constraint(context.surface, obj, obj.x_constraint().encoding(),
- std_encoding_consts.HORIZONTAL, 0, hv/4);
-
- /* y constraint edges */
- draw_constraint(context.surface, obj, obj.y_constraint().encoding(),
- std_encoding_consts.VERTICAL, wv/4, 0);
-
- /* w constraint edges */
- draw_constraint(context.surface, obj, obj.w_constraint().encoding(),
- std_encoding_consts.HORIZONTAL, wv, hv*3/4);
-
- /* h constraint edges */
- draw_constraint(context.surface, obj, obj.h_constraint().encoding(),
- std_encoding_consts.VERTICAL, wv*3/4, hv);
-
- /* draw visible constraint edges */
- draw_constraint(context.surface, obj, obj.visible_constraint().encoding(),
- std_encoding_consts.VERTICAL, 0, 0);
-
- /* draw enabled constraint edges */
- draw_constraint(context.surface, obj, obj.enabled_constraint().encoding(),
- std_encoding_consts.VERTICAL, 0, 0);
-
- /* draw part_a constraint edges */
- draw_constraint(context.surface, obj, obj.part_a_constraint().encoding(),
- std_encoding_consts.VERTICAL, wv/2, hv/2);
-
- /* draw part_B constraint edges */
- draw_constraint(context.surface, obj, obj.part_b_constraint().encoding(),
- std_encoding_consts.VERTICAL, wv/2, hv/2);
-
-
- /* don't actually add the object to the result collection */
- return false;
- }
- //had:
- //* @exception sub_arctic.exception.bad_value thrown if the parameters
- //* argument is not a sem_draw_context object.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Draw the dependency lines for a given encoded constraint (which is attached
- * to the given object and uses the given orientation). The lines start at
- * locations indicated by the dependencies of the encoded constraint, and
- * end at the given position.<p>
- *
- * @param drawable surf where the drawing takes place
- * @param interactor obj object the constraint is attached to (hence where * dependencies are relative to).
- * @param int enc encoding of the constraint.
- * @param int orient orientation of the constraint.
- * @param int xpos x position of edge end points
- * @param int ypos y position of edge end points
- */
- protected void draw_constraint(drawable surf, interactor obj, int enc,
- int orient, int xpos, int ypos)
- {
- Vector dep_list = null;
- int i, from_part;
- interactor from_obj;
- Point f_pt;
- int from_x = 0;
- int from_y = 0;
-
- /* get the dependency edge list for the encoded constraint */
- dep_list = std_constraint_impl.the_impl().depend_list(enc, obj, orient);
-
- /* draw one edge for each entry (each pair) in dependency list */
- for (i = 0; i < dep_list.size(); i += 2)
- {
- /* pull out the object and part within it */
- from_obj = (interactor)dep_list.elementAt(i);
- from_part = ((Integer)dep_list.elementAt(i+1)).intValue();
-
- /* draw from position corresponding to the part */
- switch(from_part)
- {
- case X:
- from_x = 0;
- from_y = from_obj.h()/4;
- break;
- case Y:
- from_x = from_obj.w()/4;
- from_y = 0;
- break;
- case W:
- from_x = from_obj.w();
- from_y = from_obj.h()*3/4;
- break;
- case H:
- from_x = from_obj.w()*3/4;
- from_y = from_obj.h();
- break;
- case VISIBLE:
- from_x = 0;
- from_y = 0;
- break;
- case ENABLED:
- from_x = 0;
- from_y = 0;
- break;
- case PART_A:
- from_x = from_obj.w()/2;
- from_y = from_obj.h()/2;
- break;
- case PART_B:
- from_x = from_obj.w()/2;
- from_y = from_obj.h()/2;
- break;
- }
-
- /* put from_x, from_y into local coordinates of obj */
- f_pt = obj.global_to_local(from_obj.local_to_global(from_x, from_y));
-
- /* draw the arrow */
- surf.draw_line(f_pt.x, f_pt.y, xpos, ypos);
- surf.fill_arrowhead(f_pt.x, f_pt.y, xpos, ypos);
- }
- }
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- };
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-